package com.xsd.prc;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @Description: 异步回调
 * @Author: zhoufuzong
 * @Created: 2021-01-06 20:26:11
 * @Version: 1.1.0
 */

public class CompletableFutureDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> completableFuture = CompletableFuture.supplyAsync(()->
        {System.out.println(Thread.currentThread().getName()+"\t 有返回，insert sql ok");
        return 1024;
        });

        System.out.println(completableFuture.whenComplete((t, u) -> {
            System.out.println("******t:" + t);
            System.out.println("******u:" + u);
        }).exceptionally(f -> {
            System.out.println(f.getMessage());
            return 4444;
        }).get());
    }
}
